Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
feathers-errors
Advanced tools
Error handling mixin for Feathers apps.
Feathers errors come with feathers by default. So typically you don't need to install it at all. However you can also use feathers-errors
with express directly as well. In that case you install the module with: npm install feathers-errors --save
var feathers = require('feathers');
var memory = require('feathers-memory');
var app = feathers()
.use('/users', memory)
.configure(feathers.errors());
var app = require('express');
var errors = require('feathers-errors');
var app = express()
.use(errors.fourOhFour)
.use(errors.handler);
Pro Tip: Just like express middleware, order matters. So your error handling should typically be configured last.
BadRequest
: 400NotAuthenticated
: 401PaymentError
: 402Forbidden
: 403NotFound
: 404MethodNotAllowed
: 405NotAcceptable
: 406Timeout
: 408Conflict
: 409Unprocessable
: 422GeneralError
: 500NotImplemented
: 501Unavailable
: 503Pro Tip: Feathers service adapters (ie. mongodb, memory, etc.) already emit the appropriate errors for you. :-)
var feathers = require('feathers');
var app = feathers();
var userService = {
find: function(params, callback) {
// If you were to create an error yourself.
callback(new this.app.errors.NotFound('User does not exist'));
// You can also simply do something like this if you
// just want to fire back a simple 500 error with your
// custom message.
//
// callback('A generic server error');
},
setup: function(app){
this.app = app;
}
};
app.use('/users', userService)
.configure(feathers.errors());
We have conveniently created a basic 404 middleware already for you. If you want to override it, do this:
var feathers = require('feathers');
var app = feathers();
app.use('/users', userService)
.configure(feathers.errors({
fourOhFour: function(req, res, next){
// Handle your 404's some special way
}
}));
We already have an error handler that gets added to the middleware stack when you call feathers.errors()
. However, if you want customize how you handle errors you can do so like this:
var feathers = require('feathers');
var app = feathers();
app.use('/users', userService)
.configure(feathers.errors({
handler: function(req, res, next){
// Handle your errors the way you want
}
}));
See examples directory.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
0.2.0
0.1.4
missing
to fourOhFour
0.1.3
0.1.2
0.1.1
var types = require('feathers-errors').types;
0.1.0
Copyright (c) 2014 Eric Kryski Licensed under the MIT license.
FAQs
Common error types for feathers apps
The npm package feathers-errors receives a total of 2,849 weekly downloads. As such, feathers-errors popularity was classified as popular.
We found that feathers-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.